package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Description:
 * Date: 2025-10-18
 * Time: 18:57
 */
public class ReturnBook implements IOperation{
    public void work(BookList bookList) {
        System.out.println("归还图书！！！");

        System.out.println("请输入你要归还的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currentSize = bookList.getCurrentSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)){
                if(book.getisBorrow() == false){
                    System.out.println("该书未被借出！！！");
                    return;
                }
                book.setisBorrow(false);
                System.out.println("归还成功");
                return;
            }
        }
        System.out.println("没有你所要归还的图书！！！");
    }
}
